package com.doubi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doubi.entity.ResponseEntity;
import com.doubi.entity.Userinfo;
import com.doubi.mapper.UserinfoMapper;
import com.doubi.service.UserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper,Userinfo> implements UserinfoService {
    @Autowired
    private UserinfoMapper userinfoMapper;
    //修改个人信息
    @Override
    public int saveUserInfo(Userinfo userinfo) {
        return userinfoMapper.saveUserInfo(userinfo);
    }
    //查询手机号
    @Override
    public Integer selectIphone(String phoneNum, int userId) {
        return userinfoMapper.selectIphone(phoneNum,userId);
    }

    @Override
    public Integer saveImg(String frilmsg, Integer userId) {
        return userinfoMapper.saveImg(frilmsg,userId);
    }

    @Override
    public ResponseEntity userConditionQuery(Integer pageNo, Integer pageSize, String selUserName, String selUserAccount, String selPhone, String selWeiXin) {
        ResponseEntity responseEntity = new ResponseEntity();
        //开启分页
        IPage<Userinfo> page = new Page<>(pageNo, pageSize);
        //List<Userinfo> user = userinfoMapper.userConditionQuery(selUserName,selUserAccount,selPhone,selWeiXin);
        QueryWrapper<Userinfo> queryWrapper = new QueryWrapper<>();
        if (selUserName != null && !selUserName.equals("")) {
            queryWrapper.like("userName", selUserName);
        }
        if (selUserAccount != null && !selUserAccount.equals("")) {
            queryWrapper.like("userAccount", selUserAccount);
        }
        if (selPhone != null && !selPhone.equals("")) {
            queryWrapper.like("phoneNum", selPhone);
        }
        if (selWeiXin != null && !selWeiXin.equals("")) {
            queryWrapper.like("weixinId", selWeiXin);
        }
        //创建分页的对象
        IPage<Userinfo> userPage=this.page(page, queryWrapper);
        //设置响应对象的值
        responseEntity.setCount(userPage.getTotal());
        //设置行数据
        responseEntity.addDate("tableData",userPage.getRecords());
        return responseEntity;
    }

    @Override
    public int delUserByIds(List<Integer> userIds) {
        return userinfoMapper.delUserByIds(userIds);
    }
}
